package com.xhg.validator;

import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;
import com.xhg.model.User;

/**
 * UserValidator.
 */
public class UserValidator extends Validator {
	/**
	 * 校验方法
	 */
	protected void validate(Controller controller) {
		validateRequiredString("user.userName", "msg", "用户名不能为空!");
		validateRequiredString("user.password", "msg", "密码不能为空");
	}
	/**
	 * 效验失败时调用
	 */
	protected void handleError(Controller c) {
		c.keepModel(User.class);
		String actionKey = getActionKey();
		if (actionKey.equals("/login")){//登陆action
			c.render("login.jsp");
		}else if (actionKey.equals("/user/add")){//添加action
			c.render("toAdd.jsp");
		}else if (actionKey.equals("/user/upd")){//修改action
			c.render("toUpd.jsp");
		}
	}
}
